{extend name="platform/base" /}
{block name="resources"/}
<style>
p {
    margin: 6px 0 10px;
}
.imglogo{
	min-height:80px;
}
.hint{
	color:#bbb;
	margin-top:10px;
	white-space:nowrap;
	display:none;
}
</style>

{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 版权设置 </header>
	<div class="panel-body">
		<form class="form-horizontal">
            <div class="form-group">
                 <label class="col-sm-2 control-label">保存方式</label>
				<div class="col-sm-4" id="select-box">
					<select class="form-control m-b" id="type"onchange="selectConfig();">
						<option value="1">本地</option>
						<option value="2">七牛</option>
						<option value="3">阿里云</option>
					</select>
					<p class="hint" >七牛云构建了基于容器的计算平台，并基于容器平台构建了功能丰富且开放性的智能媒体云平台。</p>
					<p class="hint" >您只需考虑怎么处理数据，而无需考虑数据的规模和系统性能。</p>
				</div>
           </div>
           <div class="config-box config-data2" >
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Accesskey</label>
					<div class="col-md-4" style="width:80%;">
						<input id="Accesskey" type="text"  value="{$config_data['data']['qiniu']['Accesskey']}" class="form-control" style="width:30%;">
						<p style="color:#BBB;margin-top:10px;">用于签名的公钥</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Secretkey</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id="Secretkey" value="{$config_data['data']['qiniu']['Secretkey']}" style="width:30%;">
						<p style="color:#BBB;margin-top:10px;">用于签名的私钥</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Bucket</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id="Bucket" value="{$config_data['data']['qiniu']['Bucket']}" style="width:30%;">						
						<p style="color:#BBB;margin-top:10px;">请保证bucket为可公共读取的</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Url</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id="QiniuUrl" value="{$config_data['data']['qiniu']['QiniuUrl']}" style="width:30%;">
						<p style="color:#BBB;margin-top:10px;">七牛支持用户自定义访问域名。注：url开头加http://或https://结尾不加 ‘/’例：http://abc.com</p>
					</div>
				</div>
				
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="setQiniuConfigAjax()" class="btn btn-primary">保存</a>
				</div>
				</div>
			</div>
			
           <div class="config-box config-data3" >
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">accessKeyId</label>
					<div class="col-md-4" style="width:80%;">
						<input id="accessKeyId" type="text"  value="{$config_data['data']['aliyun']['accessKeyId']}" class="form-control" style="width:30%;">
						<p style="color:#BBB;margin-top:10px;">阿里云OSS用于签名的公钥</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">accessKeySecret</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id="accessKeySecret" value="{$config_data['data']['aliyun']['accessKeySecret']}" style="width:30%;">
						<p style="color:#BBB;margin-top:10px;">阿里云OSS用于签名的私钥</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">bucket</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id="bucket" value="{$config_data['data']['aliyun']['bucket']}" style="width:30%;">						
						<p style="color:#BBB;margin-top:10px;">阿里云OSS存储空间名称,请保证bucket为可公共读取的</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">上传endpoint</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id="endpoint" value="{$config_data['data']['aliyun']['endpoint']}" style="width:30%;">
						<p style="color:#BBB;margin-top:10px;">上传使用。阿里云OSS地域节点。注：url开头加http://结尾不加 ‘/’例：http://abc.com</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">访问域名</label>
					<div class="col-md-4" style="width:80%;">
						<input type="text" class="form-control" id="out_url" value="{$config_data['data']['aliyun']['out_url']}" style="width:30%;">
						<p style="color:#BBB;margin-top:10px;">该空间外网访问的Bucket域名或是阿里云加速访问域名。注：url开头加http://结尾不加 ‘/’例：http://abc.com</p>
					</div>
				</div>
				<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="setQiniuConfigAjax()" class="btn btn-primary">保存</a>
				</div>
				</div>
			</div>
		</form>
	</div>
</section>
<script>

var flag = false;
$(function(){
	$("#type").val(parseInt("{$config_data['type']}"));
	selectConfig();
	
/* 	$("input[name='thumb_type']").click(function(){
		$("input[name='thumb_type']").prop("checked", false).parent("i").removeClass('selected');
		$(this).prop("checked", true).addClass('selected');
	})
	
	$("input[name='water_position']").click(function(){
		$("input[name='water_position']").prop("checked", false).parent("i").removeClass('selected');
		$(this).prop("checked", true).addClass('selected');
	}) */
})

/**
 * 保存保存数据
 */
function setQiniuConfigAjax(){
	//七牛云
	var Accesskey = $("#Accesskey").val();
	var Secretkey = $("#Secretkey").val();
	var Bucket = $("#Bucket").val();
	var QiniuUrl = $("#QiniuUrl").val();
    
	//阿里云
    var accessKeyId = $("#accessKeyId").val();
    var accessKeySecret = $("#accessKeySecret").val();
    var endpoint = $("#endpoint").val();
    var bucket = $("#bucket").val();
    var out_url = $("#out_url").val();
    //var cdn_url = $("#cdn_url").val();
   
	$.ajax({
		type:"post",
		url : "{:__URL('PLATFORM_MAIN/config/setQiniuconfig')}",
		async : true,
		data : {
			//七牛云
			"Accesskey" : Accesskey,
			'Secretkey' : Secretkey,
			"Bucket" : Bucket,
			"QiniuUrl" : QiniuUrl,
			//阿里云
			'accessKeyId' : accessKeyId,
            'accessKeySecret' : accessKeySecret,
            'endpoint' : endpoint,
            'bucket' : bucket,
            'out_url' : out_url,
            //'cdn_url' : cdn_url,
		},
		success : function(data){
			if(data['code'] > 0)
				{
					showMessage('success', data["message"]);
					location.href=__URL("PLATFORM_MAIN/config/uploadtype");
				}else{
					showMessage('error', data["message"]);
				}
		}
	})
}
	
function selectConfig(){
	var type = $("#type").val();
	$(".config-box").hide();
	$(".config-data"+type).show();
	if(type == '1'){
		$('#select-box .hint').hide();
	}else{
		$('#select-box .hint').show();
	}
	if(flag){
		$.ajax({
			type:"post",
			url : "{:__URL('PLATFORM_MAIN/config/setuploadtype')}",
			async : true,
			data : {
				"type" : type
			},
			success : function(data){
				if(data['code'] > 0){
					showTip(data.message,"success");
				}else{
					showTip(data.message,"error");
				}
			}
		})
	}else{
		flag = true;
	}
}
</script>
{/block}